home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / bfd / reloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-02  |  23.0 KB  |  862 lines

  1. /* BFD support for handling relocation entries.
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /*
  22. SECTION
  23.     Relocations
  24.  
  25.     BFD maintains relocations in much the same was as it maintains
  26.     symbols; they are left alone until required, then read in
  27.     en-mass and traslated into an internal form. There is a common
  28.     routine <<bfd_perform_relocation>> which acts upon the
  29.     canonical form to to the actual fixup.
  30.  
  31.     Note that relocations are maintained on a per section basis,
  32.     whilst symbols are maintained on a per BFD basis.
  33.  
  34.     All a back end has to do to fit the BFD interface is to create
  35.     as many <<struct reloc_cache_entry>> as there are relocations
  36.     in a particuar section, and fill in the right bits:
  37.  
  38. @menu
  39. @* typedef arelent::
  40. @* howto manager::
  41. @end menu
  42.  
  43. */
  44. #include "bfd.h"
  45. #include "sysdep.h"
  46. #include "libbfd.h"
  47. #include "seclet.h"
  48. /*doc*
  49. INODE
  50.     typedef arelent, howto manager, Relocations, Relocations
  51.  
  52. SUBSECTION
  53.     typedef arelent
  54.  
  55.     This is the structure of a relocation entry:
  56.  
  57. CODE_FRAGMENT
  58. .
  59. .typedef enum bfd_reloc_status 
  60. .{
  61. .       {* No errors detected *}
  62. .  bfd_reloc_ok,
  63. .
  64. .       {* The relocation was performed, but there was an overflow. *}
  65. .  bfd_reloc_overflow,
  66. .
  67. .       {* The address to relocate was not within the section supplied*}
  68. .  bfd_reloc_outofrange,
  69. .
  70. .       {* Used by special functions *}
  71. .  bfd_reloc_continue,
  72. .
  73. .       {* Unused *}
  74. .  bfd_reloc_notsupported,
  75. .
  76. .       {* Unsupported relocation size requested.  *}
  77. .  bfd_reloc_other,
  78. .
  79. .       {* The symbol to relocate against was undefined.*}
  80. .  bfd_reloc_undefined,
  81. .
  82. .       {* The relocation was performed, but may not be ok - presently
  83. .          generated only when linking i960 coff files with i960 b.out
  84. .          symbols. *}
  85. .  bfd_reloc_dangerous
  86. . }
  87. . bfd_reloc_status_type;
  88. .
  89. .
  90. .typedef struct reloc_cache_entry 
  91. .{
  92. .       {* A pointer into the canonical table of pointers  *}
  93. .  struct symbol_cache_entry **sym_ptr_ptr;
  94. .
  95. .       {* offset in section *}
  96. .  rawdata_offset address;
  97. .
  98. .       {* addend for relocation value *}
  99. .  bfd_vma addend;    
  100. .
  101. .       {* Pointer to how to perform the required relocation *}
  102. .  CONST struct reloc_howto_struct *howto;
  103. .
  104. .} arelent;
  105.  
  106. */
  107.  
  108. /*
  109. DESCRIPTION
  110.  
  111.         Here is a description of each of the fields within a relent:
  112.  
  113.         o sym_ptr_ptr
  114.  
  115.         The symbol table pointer points to a pointer to the symbol
  116.         associated with the relocation request. This would naturally
  117.         be the pointer into the table returned by the back end's
  118.         get_symtab action. @xref{Symbols}. The symbol is referenced
  119.         through a pointer to a pointer so that tools like the linker
  120.         can fix up all the symbols of the same name by modifying only
  121.         one pointer. The relocation routine looks in the symbol and
  122.         uses the base of the section the symbol is attached to and the
  123.         value of the symbol as the initial relocation offset. If the
  124.         symbol pointer is zero, then the section provided is looked up.
  125.  
  126.         o address
  127.  
  128.         The address field gives the offset in bytes from the base of
  129.         the section data which owns the relocation record to the first
  130.         byte of relocatable information. The actual data relocated
  131.         will be relative to this point - for example, a relocation
  132.         type which modifies the bottom two bytes of a four byte word
  133.         would not touch the first byte pointed to in a big endian
  134.         world. @item addend The addend is a value provided by the back
  135.         end to be added (!) to the relocation offset. Its
  136.         interpretation is dependent upon the howto. For example, on
  137.         the 68k the code:
  138.  
  139.  
  140. |        char foo[];
  141. |        main()
  142. |                {
  143. |                return foo[0x12345678];
  144. |                }
  145.  
  146.         Could be compiled into:
  147.  
  148. |        linkw fp,#-4
  149. |        moveb @@#12345678,d0
  150. |        extbl d0
  151. |        unlk fp
  152. |        rts
  153.  
  154.  
  155.         This could create a reloc pointing to foo, but leave the
  156.         offset in the data (something like)
  157.  
  158.  
  159. |RELOCATION RECORDS FOR [.text]:
  160. |offset   type      value 
  161. |00000006 32        _foo
  162. |
  163. |00000000 4e56 fffc          ; linkw fp,#-4
  164. |00000004 1039 1234 5678     ; moveb @@#12345678,d0
  165. |0000000a 49c0               ; extbl d0
  166. |0000000c 4e5e               ; unlk fp
  167. |0000000e 4e75               ; rts
  168.  
  169.  
  170.         Using coff and an 88k, some instructions don't have enough
  171.         space in them to represent the full address range, and
  172.         pointers have to be loaded in two parts. So you'd get something like:
  173.  
  174.  
  175. |        or.u     r13,r0,hi16(_foo+0x12345678)
  176. |        ld.b     r2,r13,lo16(_foo+0x12345678)
  177. |        jmp      r1
  178.  
  179.  
  180.         This whould create two relocs, both pointing to _foo, and with
  181.         0x12340000 in their addend field. The data would consist of:
  182.  
  183.  
  184. |RELOCATION RECORDS FOR [.text]:
  185. |offset   type      value 
  186. |00000002 HVRT16    _foo+0x12340000
  187. |00000006 LVRT16    _foo+0x12340000
  188.  
  189. |00000000 5da05678           ; or.u r13,r0,0x5678
  190. |00000004 1c4d5678           ; ld.b r2,r13,0x5678
  191. |00000008 f400c001           ; jmp r1
  192.  
  193.  
  194.         The relocation routine digs out the value from the data, adds
  195.         it to the addend to get the original offset and then adds the
  196.         value of _foo. Note that all 32 bits have to be kept around
  197.         somewhere, to cope with carry from bit 15 to bit 16.
  198.  
  199.         On further example is the sparc and the a.out format. The
  200.         sparc has a similar problem to the 88k, in that some
  201.         instructions don't have room for an entire offset, but on the
  202.         sparc the parts are created odd sized lumps. The designers of
  203.         the a.out format chose not to use the data within the section
  204.         for storing part of the offset; all the offset is kept within
  205.         the reloc. Any thing in the data should be ignored. 
  206.  
  207. |        save %sp,-112,%sp
  208. |        sethi %hi(_foo+0x12345678),%g2
  209. |        ldsb [%g2+%lo(_foo+0x12345678)],%i0
  210. |        ret
  211. |        restore
  212.  
  213.         Both relocs contains a pointer to foo, and the offsets would
  214.         contain junk.
  215.  
  216.  
  217. |RELOCATION RECORDS FOR [.text]:
  218. |offset   type      value 
  219. |00000004 HI22      _foo+0x12345678
  220. |00000008 LO10      _foo+0x12345678
  221.  
  222. |00000000 9de3bf90     ; save %sp,-112,%sp
  223. |00000004 05000000     ; sethi %hi(_foo+0),%g2
  224. |00000008 f048a000     ; ldsb [%g2+%lo(_foo+0)],%i0
  225. |0000000c 81c7e008     ; ret
  226. |00000010 81e80000     ; restore
  227.  
  228.  
  229.         o howto 
  230.  
  231.         The howto field can be imagined as a
  232.         relocation instruction. It is a pointer to a struct which
  233.         contains information on what to do with all the other
  234.         information in the reloc record and data section. A back end
  235.         would normally have a relocation instruction set and turn
  236.         relocations into pointers to the correct structure on input -
  237.         but it would be possible to create each howto field on demand.
  238.         
  239. */
  240.  
  241.  
  242. /*
  243. SUBSUBSECTION 
  244.         <<reloc_howto_type>>
  245.  
  246.         The <<reloc_howto_type>> is a structure which contains all the
  247.         information that BFD needs to know to tie up a back end's data.
  248.  
  249. CODE_FRAGMENT
  250. .struct symbol_cache_entry;        {* Forward declaration *}
  251. .
  252. .typedef CONST struct reloc_howto_struct 
  253. .{ 
  254. .       {*  The type field has mainly a documetary use - the back end can
  255. .           to what it wants with it, though the normally the back end's
  256. .           external idea of what a reloc number would be would be stored
  257. .           in this field. For example, the a PC relative word relocation
  258. .           in a coff environment would have the type 023 - because that's
  259. .           what the outside world calls a R_PCRWORD reloc. *}
  260. .  unsigned int type;
  261. .
  262. .       {*  The value the final relocation is shifted right by. This drops
  263. .           unwanted data from the relocation.  *}
  264. .  unsigned int rightshift;
  265. .
  266. .       {*  The size of the item to be relocated - 0, is one byte, 1 is 2
  267. .           bytes, 3 is four bytes. *}
  268. .  unsigned int size;
  269. .
  270. .       {*  Now obsolete *}
  271. .  unsigned int bitsize;
  272. .
  273. .       {*  Notes that the relocation is relative to the location in the
  274. .           data section of the addend. The relocation function will
  275. .           subtract from the relocation value the address of the location
  276. .           being relocated. *}
  277. .  boolean pc_relative;
  278. .
  279. .       {*  Now obsolete *}
  280. .  unsigned int bitpos;
  281. .
  282. .       {*  Now obsolete *}
  283. .  boolean absolute;
  284. .
  285. .       {* Causes the relocation routine to return an error if overflow
  286. .          is detected when relocating. *}
  287. .  boolean complain_on_overflow;
  288. .
  289. .       {* If this field is non null, then the supplied function is
  290. .          called rather than the normal function. This allows really
  291. .          strange relocation methods to be accomodated (eg, i960 callj
  292. .          instructions). *}
  293. .  bfd_reloc_status_type EXFUN ((*special_function), 
  294. .                        (bfd *abfd,
  295. .                         arelent *reloc_entry,
  296. .                                            struct symbol_cache_entry *symbol,
  297. .                                            PTR data,
  298. .                                            asection *input_section));
  299. .
  300. .       {* The textual name of the relocation type. *}
  301. .  char *name;
  302. .
  303. .       {* When performing a partial link, some formats must modify the
  304. .          relocations rather than the data - this flag signals this.*}
  305. .  boolean partial_inplace;
  306. .
  307. .       {* The src_mask is used to select what parts of the read in data
  308. .          are to be used in the relocation sum. Eg, if this was an 8 bit
  309. .          bit of data which we read and relocated, this would be
  310. .          0x000000ff. When we have relocs which have an addend, such as
  311. .          sun4 extended relocs, the value in the offset part of a
  312. .          relocating field is garbage so we never use it. In this case
  313. .          the mask would be 0x00000000. *}
  314. .  bfd_word src_mask;
  315. .
  316. .       {* The dst_mask is what parts of the instruction are replaced
  317. .          into the instruction. In most cases src_mask == dst_mask,
  318. .          except in the above special case, where dst_mask would be
  319. .          0x000000ff, and src_mask would be 0x00000000.   *}
  320. .  bfd_word dst_mask;           
  321. .
  322. .       {* When some formats create PC relative instructions, they leave
  323. .          the value of the pc of the place being relocated in the offset
  324. .          slot of the instruction, so that a PC relative relocation can
  325. .          be made just by adding in an ordinary offset (eg sun3 a.out).
  326. .          Some formats leave the displacement part of an instruction
  327. .          empty (eg m88k bcs), this flag signals the fact.*}
  328. .  boolean pcrel_offset;
  329. .
  330. .} reloc_howto_type;
  331.  
  332. */
  333.  
  334. /*
  335. FUNCTION
  336.     the HOWTO macro
  337.  
  338. DESCRIPTION
  339.     The HOWTO define is horrible and will go away.
  340.  
  341.  
  342. .#define HOWTO(C, R,S,B, P, BI, ABS, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
  343. .  {(unsigned)C,R,S,B, P, BI, ABS,O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC}
  344.  
  345. DESCRIPTION
  346.     And will be replaced with the totally magic way. But for the
  347.     moment, we are compatible, so do it this way..
  348.  
  349.  
  350. .#define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,false,false,FUNCTION, NAME,false,0,0,IN)
  351. .
  352. DESCRIPTION
  353.     Helper routine to turn a symbol into a relocation value.
  354.  
  355. .#define HOWTO_PREPARE(relocation, symbol)      \
  356. .  {                                            \
  357. .  if (symbol != (asymbol *)NULL) {             \
  358. .    if (symbol->section == &bfd_com_section) { \
  359. .      relocation = 0;                          \
  360. .    }                                          \
  361. .    else {                                     \
  362. .      relocation = symbol->value;              \
  363. .    }                                          \
  364. .  }                                            \
  365. .}                      
  366.  
  367. */
  368.  
  369. /*
  370. TYPEDEF
  371.     reloc_chain
  372.  
  373. DESCRIPTION
  374.  
  375.     How relocs are tied together
  376.  
  377. .typedef unsigned char bfd_byte;
  378. .
  379. .typedef struct relent_chain {
  380. .  arelent relent;
  381. .  struct   relent_chain *next;
  382. .} arelent_chain;
  383.  
  384. */
  385.  
  386.  
  387.  
  388. /*
  389. FUNCTION 
  390.     bfd_perform_relocation
  391.  
  392. SYNOPSIS
  393.     bfd_reloc_status_type
  394.                 bfd_perform_relocation
  395.                         (bfd * abfd,
  396.                         arelent *reloc_entry,
  397.                         PTR data,
  398.                         asection *input_section,
  399.                         bfd *output_bfd);
  400.  
  401. DESCRIPTION
  402.     If an output_bfd is supplied to this function the generated
  403.     image will be relocatable, the relocations are copied to the
  404.     output file after they have been changed to reflect the new
  405.     state of the world. There are two ways of reflecting the
  406.     results of partial linkage in an output file; by modifying the
  407.     output data in place, and by modifying the relocation record.
  408.     Some native formats (eg basic a.out and basic coff) have no
  409.     way of specifying an addend in the relocation type, so the
  410.     addend has to go in the output data.  This is no big deal
  411.     since in these formats the output data slot will always be big
  412.     enough for the addend. Complex reloc types with addends were
  413.     invented to solve just this problem.
  414.  
  415. */
  416.  
  417.  
  418. bfd_reloc_status_type
  419. DEFUN(bfd_perform_relocation,(abfd,
  420.                               reloc_entry,
  421.                               data,
  422.                               input_section,
  423.                               output_bfd),
  424.       bfd *abfd AND
  425.       arelent *reloc_entry AND
  426.       PTR data AND
  427.       asection *input_section AND
  428.       bfd *output_bfd)
  429. {
  430.   bfd_vma relocation;
  431.   bfd_reloc_status_type flag = bfd_reloc_ok;
  432.   bfd_vma addr = reloc_entry->address ;
  433.   bfd_vma output_base = 0;
  434.   reloc_howto_type *howto = reloc_entry->howto;
  435.   asection *reloc_target_output_section ;
  436.  
  437.   asymbol *symbol;
  438.  
  439.   symbol = *( reloc_entry->sym_ptr_ptr);
  440.   if ((symbol->section == &bfd_und_section) && output_bfd == (bfd *)NULL) {
  441.       flag = bfd_reloc_undefined;
  442.     }
  443.  
  444.   if (howto->special_function){
  445.       bfd_reloc_status_type cont;
  446.       cont = howto->special_function(abfd,
  447.                      reloc_entry,
  448.                      symbol,
  449.                      data,
  450.                      input_section);
  451.       if (cont != bfd_reloc_continue) return cont;
  452.     }
  453.  
  454.   /* 
  455.     Work out which section the relocation is targetted at and the
  456.     initial relocation command value.
  457.     */
  458.  
  459.  
  460.   if (symbol->section == &bfd_com_section) {
  461.       relocation = 0;
  462.     }
  463.   else {
  464.       relocation = symbol->value;
  465.     }
  466.  
  467.  
  468.   reloc_target_output_section = symbol->section->output_section;
  469.  
  470.   if (output_bfd && howto->partial_inplace==false) {
  471.       output_base = 0;
  472.     }
  473.   else {
  474.       output_base = reloc_target_output_section->vma;
  475.  
  476.     }
  477.  
  478.   relocation += output_base +   symbol->section->output_offset;
  479.   
  480.  
  481.   relocation += reloc_entry->addend ;
  482.  
  483.  
  484.   if(reloc_entry->address > input_section->_cooked_size)
  485.   {
  486.     return bfd_reloc_outofrange;
  487.   }
  488.           
  489.  
  490.   if (howto->pc_relative == true)
  491.   {
  492.     /*
  493.       Anything which started out as pc relative should end up that
  494.       way too. 
  495.       
  496.       There are two ways we can see a pcrel instruction. Sometimes
  497.       the pcrel displacement has been partially calculated, it
  498.       includes the distance from the start of the section to the
  499.       instruction in it (eg sun3), and sometimes the field is
  500.       totally blank - eg m88kbcs.
  501.       */
  502.  
  503.         
  504.     relocation -= 
  505.      input_section->output_section->vma + input_section->output_offset;
  506.  
  507.     if (howto->pcrel_offset == true) {
  508.     relocation -= reloc_entry->address;
  509.       }
  510.  
  511.   }
  512.  
  513.   if (output_bfd!= (bfd *)NULL) {
  514.       if ( howto->partial_inplace == false)  {
  515.       /*
  516.         This is a partial relocation, and we want to apply the relocation
  517.         to the reloc entry rather than the raw data. Modify the reloc
  518.         inplace to reflect what we now know.
  519.         */
  520.       reloc_entry->addend = relocation  ;
  521.       reloc_entry->address +=  input_section->output_offset;
  522.       return flag;
  523.     }
  524.       else 
  525.       {
  526.     /* This is a partial relocation, but inplace, so modify the
  527.        reloc record a bit. 
  528.        
  529.        If we've relocated with a symbol with a section, change
  530.        into a ref to  the section belonging to the symbol
  531.        */
  532.       reloc_entry->addend = relocation  ;
  533.       reloc_entry->address +=  input_section->output_offset;
  534.  
  535.  
  536.       }
  537.     }
  538.   else 
  539.   {
  540.     
  541.   reloc_entry->addend = 0;
  542. }
  543.   
  544.  
  545.  
  546.   /* 
  547.     Either we are relocating all the way, or we don't want to apply
  548.     the relocation to the reloc entry (probably because there isn't
  549.     any room in the output format to describe addends to relocs)
  550.     */
  551.   relocation >>= howto->rightshift;
  552.  
  553.   /* Shift everything up to where it's going to be used */
  554.    
  555.   relocation <<= howto->bitpos;
  556.  
  557.   /* Wait for the day when all have the mask in them */
  558.  
  559.   /* What we do:
  560.      i instruction to be left alone
  561.      o offset within instruction
  562.      r relocation offset to apply
  563.      S src mask
  564.      D dst mask
  565.      N ~dst mask
  566.      A part 1
  567.      B part 2
  568.      R result
  569.      
  570.      Do this:
  571.      i i i i i o o o o o        from bfd_get<size>
  572.      and           S S S S S    to get the size offset we want
  573.      +   r r r r r r r r r r  to get the final value to place
  574.      and           D D D D D  to chop to right size
  575.      -----------------------
  576.      A A A A A 
  577.      And this:
  578.      ...   i i i i i o o o o o  from bfd_get<size>
  579.      and   N N N N N            get instruction
  580.      -----------------------
  581.      ...   B B B B B
  582.      
  583.      And then:       
  584.      B B B B B       
  585.      or              A A A A A     
  586.      -----------------------
  587.      R R R R R R R R R R        put into bfd_put<size>
  588.      */
  589.  
  590. #define DOIT(x) \
  591.   x = ( (x & ~howto->dst_mask) | (((x & howto->src_mask) +  relocation) & howto->dst_mask))
  592.  
  593.    switch (howto->size)
  594.    {
  595.    case 0:
  596.    {
  597.      char x = bfd_get_8(abfd, (char *)data + addr);
  598.      DOIT(x);
  599.      bfd_put_8(abfd,x, (unsigned char *) data + addr);
  600.    }
  601.      break;
  602.  
  603.    case 1:
  604.    { 
  605.      short x = bfd_get_16(abfd, (bfd_byte *)data + addr);
  606.      DOIT(x);
  607.      bfd_put_16(abfd, x,   (unsigned char *)data + addr);
  608.    }
  609.      break;
  610.    case 2:
  611.    {
  612.      long  x = bfd_get_32(abfd, (bfd_byte *) data + addr);
  613.      DOIT(x);
  614.      bfd_put_32(abfd,x,    (bfd_byte *)data + addr);
  615.    }      
  616.      break;
  617.    case 3:
  618.  
  619.      /* Do nothing */
  620.      break;
  621.    default:
  622.      return bfd_reloc_other;
  623.    }
  624.  
  625.   return flag;
  626. }
  627.  
  628.  
  629.  
  630. /*
  631. INODE
  632.     howto manager,  , typedef arelent, Relocations
  633.  
  634. SECTION
  635.     The howto manager 
  636.  
  637.     When an application wants to create a relocation, but doesn't
  638.     know what the target machine might call it, it can find out by
  639.     using this bit of code.
  640.  
  641. */
  642.  
  643. /*
  644. TYPEDEF
  645.     bfd_reloc_code_type
  646.  
  647. DESCRIPTION
  648.     The insides of a reloc code
  649.  
  650. CODE_FRAGMENT
  651. .
  652. .typedef enum bfd_reloc_code_real 
  653. .{
  654. .       {* 16 bits wide, simple reloc *}
  655. .  BFD_RELOC_16,        
  656. .
  657. .       {* 8 bits wide, but used to form an address like 0xffnn *}
  658. .  BFD_RELOC_8_FFnn,
  659. .
  660. .       {* 8 bits wide, simple *}
  661. .  BFD_RELOC_8,
  662. .
  663. .       {* 8 bits wide, pc relative *}
  664. .  BFD_RELOC_8_PCREL,
  665. .
  666. .       {* The type of reloc used to build a contructor table - at the
  667. .          moment probably a 32 bit wide abs address, but the cpu can
  668. .          choose. *}
  669. .
  670. .  BFD_RELOC_CTOR
  671. . } bfd_reloc_code_real_type;
  672. */
  673.  
  674.  
  675.  
  676. /*
  677. SECTION
  678.     bfd_reloc_type_lookup
  679.  
  680. SYNOPSIS
  681.     CONST struct reloc_howto_struct *
  682.     bfd_reloc_type_lookup
  683.     (CONST bfd_arch_info_type *arch, bfd_reloc_code_type code);
  684.  
  685. DESCRIPTION
  686.     This routine returns a pointer to a howto struct which when
  687.     invoked, will perform the supplied relocation on data from the
  688.     architecture noted.
  689.  
  690. */
  691.  
  692.  
  693. CONST struct reloc_howto_struct *
  694. DEFUN(bfd_reloc_type_lookup,(arch, code),
  695.     CONST bfd_arch_info_type *arch  AND
  696.     bfd_reloc_code_type code)
  697. {
  698.   return arch->reloc_type_lookup(arch, code);
  699. }
  700.  
  701. static reloc_howto_type bfd_howto_32 =
  702.  HOWTO(0, 00,2,32,false,0,false,true,0,"VRT32", false,0xffffffff,0xffffffff,true);
  703.  
  704.  
  705. /*
  706. INTERNAL_FUNCTION
  707.     bfd_default_reloc_type_lookup
  708.  
  709. SYNOPSIS
  710.     CONST struct reloc_howto_struct *bfd_default_reloc_type_lookup
  711.     (CONST struct bfd_arch_info *,
  712.          bfd_reloc_code_type  code);
  713.  
  714. DESCRIPTION
  715.     Provides a default relocation lookuperer for any architectue 
  716.  
  717.  
  718. */
  719. CONST struct reloc_howto_struct *
  720. DEFUN(bfd_default_reloc_type_lookup,(arch,  code),
  721.      CONST struct bfd_arch_info *arch AND
  722.       bfd_reloc_code_type  code)
  723. {
  724.     switch (code) 
  725.     {
  726.        case BFD_RELOC_CTOR:
  727.     /* The type of reloc used in a ctor, which will be as wide as the
  728.        address - so either a 64, 32, or 16 bitter.. */
  729.     switch (arch->bits_per_address) {
  730.        case 64:
  731.         BFD_FAIL();
  732.        case 32:
  733.         return &bfd_howto_32;
  734.        case 16:
  735.         BFD_FAIL();
  736.        default:
  737.         BFD_FAIL();
  738.     }
  739.        default:
  740.     BFD_FAIL();
  741.     }
  742. return (struct reloc_howto_struct *)NULL;
  743. }
  744.  
  745.  
  746. /*
  747. INTERNAL_FUNCTION
  748.     bfd_generic_relax_section
  749.  
  750. SYNOPSIS
  751.     boolean bfd_generic_relax_section
  752.      (bfd *abfd,
  753.       asection *section,
  754.       asymbol **symbols);
  755.  
  756. DESCRIPTION
  757.     Provides default handling for relaxing for back ends which
  758.     don't do relaxing - ie does nothing 
  759. */
  760.  
  761. boolean
  762. DEFUN(bfd_generic_relax_section,(abfd, section, symbols),
  763.       bfd *abfd AND
  764.       asection *section AND
  765.       asymbol **symbols)
  766. {
  767.   
  768.   return false;
  769.   
  770. }
  771.  
  772.         
  773. /*
  774. INTERNAL_FUNCTION
  775.     bfd_generic_get_relocated_section_contents
  776.  
  777. SYNOPSIS
  778.     bfd_byte *
  779.        bfd_generic_get_relocated_section_contents(bfd *abfd,
  780.          struct bfd_seclet_struct  *seclet)
  781.  
  782. DESCRIPTION
  783.     Provides default handling of relocation effort for back ends
  784.     which can't be bothered to do it efficiently.
  785.  
  786. */
  787.  
  788. bfd_byte *
  789. DEFUN(bfd_generic_get_relocated_section_contents,(abfd, seclet),
  790.       bfd *abfd AND
  791.       struct bfd_seclet_struct *seclet)
  792. {
  793.   extern bfd_error_vector_type bfd_error_vector;
  794.  
  795.   /* Get enough memory to hold the stuff */
  796.   bfd *input_bfd = seclet->u.indirect.section->owner;
  797.   asection *input_section = seclet->u.indirect.section;
  798.  
  799.   bfd_byte *data = (bfd_byte *) bfd_xmalloc(input_section->_raw_size);
  800.  
  801.   bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
  802.                                input_section);
  803.   arelent **reloc_vector = (arelent **) bfd_xmalloc(reloc_size);
  804.   
  805.   /* read in the section */
  806.   bfd_get_section_contents(input_bfd,
  807.                input_section,
  808.                data,
  809.                0,
  810.                input_section->_raw_size);
  811.   
  812. /* We're not relaxing the section, so just copy the size info */
  813.   input_section->_cooked_size = input_section->_raw_size;
  814.   input_section->reloc_done = true;
  815.   
  816.  
  817.   if (bfd_canonicalize_reloc(input_bfd, 
  818.                  input_section,
  819.                  reloc_vector,
  820.                  seclet->u.indirect.symbols) )
  821.   {
  822.     arelent **parent;
  823.     for (parent = reloc_vector;  * parent != (arelent *)NULL;
  824.      parent++) 
  825.     { 
  826.       bfd_reloc_status_type r=
  827.        bfd_perform_relocation(input_bfd,
  828.                   *parent,
  829.                   data,
  830.                   input_section, 0);
  831.       
  832.  
  833.       if (r != bfd_reloc_ok) 
  834.       {
  835.     switch (r)
  836.     {
  837.     case bfd_reloc_undefined:
  838.       bfd_error_vector.undefined_symbol(*parent, seclet);
  839.       break;
  840.     case bfd_reloc_dangerous: 
  841.       bfd_error_vector.reloc_dangerous(*parent, seclet);
  842.       break;
  843.     case bfd_reloc_outofrange:
  844.     case bfd_reloc_overflow:
  845.       bfd_error_vector.reloc_value_truncated(*parent, seclet);
  846.       break;
  847.     default:
  848.       abort();
  849.       break;
  850.     }
  851.  
  852.       }
  853.     }    
  854.   }
  855.  
  856.   free((char *)reloc_vector);
  857.   return data;
  858.  
  859.   
  860. }
  861.  
  862.